[API] Add support for W3C randomness flag#7301
Conversation
Update `TraceContextPropagator` to handle the W3C randomness flag. Contributes to open-telemetry#6768.
Add PR number.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7301 +/- ##
==========================================
+ Coverage 89.85% 89.94% +0.08%
==========================================
Files 273 275 +2
Lines 13773 13999 +226
==========================================
+ Hits 12376 12591 +215
- Misses 1397 1408 +11
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
Adds support for the W3C trace context randomness flag (bit 0x02) in TraceContextPropagator so the flag round-trips through both extract and inject paths, and updates OpenTelemetrySdkEventSource to render the full trace flags byte. Tests are extended to cover the new bit and the Dockerfile is bumped to W3C spec level 2.
Changes:
TraceContextPropagator.Injectnow writes the entire trace flags byte as hex (covering Recorded + Random), andTryExtractTraceparentrecognizes the0x02random bit.OpenTelemetrySdkEventSource.ActivityStartedformats the flags byte as 2-digit hex instead of hardcoding-00/-01.- New unit tests for extracting/injecting the random flag (alone and combined with Recorded), Dockerfile
SPEC_LEVEL=2, CHANGELOG entries.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs | Inject/extract now handle the random flag bit; minor ternary refactor in TryExtractTracestate; WriteTraceParentIntoSpan writes flags via hex helper. |
| src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs | Logs full trace flags byte using x2 formatting. |
| test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTests.cs | Adds tests for random flag (alone and combined), and invalid traceparents with -02/-03. |
| test/OpenTelemetry.Api.Tests/Context/Propagation/EnvironmentVariableCarrierTests.cs | Parameterizes round-trip test across all four flag combinations. |
| test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/Dockerfile | Bumps SPEC_LEVEL from 1 to 2. |
| src/OpenTelemetry.Api/CHANGELOG.md, src/OpenTelemetry/CHANGELOG.md | Document the changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename `f` to `propagator`. - Rename `ctx` to `context`.
Optimise the implementation.
Fix typo in comment.
Fix typo in comment.
|
I didn't check the exporter parts (OTLP, Console). IMO worth to do this. EDIT: Separate PR will be fine. |
2435127
I checked the repo again.
|
Contributes to #6768. I'm not sure if this fixes it.
Changes
Update
TraceContextPropagatorto handle the W3C randomness flag.This got flagged by the updates to .NET 11 preview.4 in #6899 and open-telemetry/opentelemetry-dotnet-contrib#3867, and it looks like we can support it without needing to have the
ActivityTraceFlags.RandomTraceIdenum value defined (dotnet/runtime#124509).Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)